var express = require('express');
var router = express.Router();
const cateDao = require('../dao/cateDao')

// 获取分类信息
router.get('/list',function(req,res,next){
    cateDao.findCateList(req,res)
})

// 新增分类信息
router.post('/add', async (req, res) => {
    try {
        await cateDao.addCate(req, res);
    } catch (error) {
        console.error(error);
        res.status(500).send({ status: 0, message: '新增失败！' });
    }
});

//  修改分类信息
router.post('/update', async (req, res) => {
    try {
        await cateDao.updateCate(req, res);
    } catch (error) {
        console.error(error);
        res.status(500).send({ status: 0, message: '修改失败！' });
    }
});

// 删除分类的路由
router.delete('/delete', async (req, res) => {
    try {
        console.log('Calling deleteCate');
        await cateDao.deleteCate(req, res);
    } catch (error) {
        console.error('Sending internal server error');
        res.status(500).json({ status: 0, message: '删除失败！' });
    }
});

module.exports = router;
